<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册页面</title>
    <%@ include file="../headJs.jsp"%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/allcss/register.css" />
    <script>
        if (window != top)
            top.location.replace(location.href);
    </script>
</head>
<body id="log" >

<div class="login-wrapper">

    <div class="login-header">
        <img src="../static/images/logo_03.png">
    </div>

    <div class=" login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-friends"></i>&nbsp;&nbsp;用户注册
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-user"></i></label>
                    <div class="layui-input-block">
                        <input name="name" type="text" lay-verify="required" placeholder="昵称"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" lay-verify="required" placeholder="账号"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" lay-verify="required" placeholder="密码"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-ok-circle"></i></label>
                    <div class="layui-input-block">
                        <input name="repassword" type="password" lay-verify="required" placeholder="确认密码"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-tree"></i></label>
                    <div class="layui-input-block">
                        <input name="age" type="number" lay-verify="required" placeholder="年龄" min="1" max="300"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-headset"></i></label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="male" title="男" >
                        <input type="radio" name="sex" value="female" title="女" checked>


                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-cellphone"></i></label>
                    <div class="layui-input-block">
                        <input name="phone" type="text" lay-verify="required" placeholder="手机号" maxlength="11"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-template-1"></i></label>
                    <div class="layui-input-block">
                        <input name="classno" type="text" lay-verify="required" placeholder="班级" maxlength="20"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-list"></i></label>
                    <div class="layui-input-block">
                        <input name="sno" type="text" lay-verify="required" placeholder="学号" maxlength="20"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-tabs"></i></label>
                    <div class="layui-input-block">
                        <input name="idcard" type="text" lay-verify="required" placeholder="身份证号" maxlength="18"
                               class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" lay-submit>注 册</button>
                </div>

            </form>
        </div>
    </div>

    <%--<div class="login-footer">
        <p>© 2018 <a href="javascript:;" target="_blank">江西信息应用职业技术学院版权所有</a></p>
        <p>
            <span><a href="https://github.com/whvcse/EasyWeb" target="_blank">前往github</a></span>
            <span><a href="https://gitee.com/whvse/EasyWeb" target="_blank">前往gitee</a></span>
            <span><a href="javascript:;" target="_blank">文档说明</a></span>
        </p>
    </div>--%>
</div>
<script>
    layui.use(['form','layer'],function () {
        var form = layui.form;
        var layer = layui.layer;


        //自定义验证规则
        /*form.verify({
            phone: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,password: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
*/



        form.on('submit(login-submit)',function (obj) {

            if(obj.field.password != obj.field.repassword){
                layer.msg('两次密码输入不一致！！！',{icon:5});
                return false;
            }

            if(!(/^1[3456789]\d{9}$/.test(obj.field.phone))){
                layer.msg('手机号格式不正确！！！',{icon:5});
                return false;
            }

            layer.load(2);
            $.post(
                '${pageContext.request.contextPath}/register/register',
                obj.field,
                function (data) {
                    if(data.code == '1000'){
                        layer.msg(data.msg,{icon:2});
                        layer.closeAll('loading');
                    } else if(data.code == 'name'){
                        layer.msg(data.msg,{icon:2});
                        layer.closeAll('loading');
                    } else if(data.code == 'username'){
                        layer.msg(data.msg,{icon:2});
                        layer.closeAll('loading');
                    } else if(data.code > 0){
                        layer.msg("注册成功，即将跳转到登录页面",{icon:1,time:2500},function () {
                            // location.replace('../login/loginForm');
                            window.location = "${pageContext.request.contextPath}/login/loginForm";
                        });
                    } else {
                        layer.msg("注册失败",{icon:2});
                        layer.closeAll('loading');
                    }
                },
                'JSON'
            );
            return false;
        })
    });

    // 图形验证码
    $('.login-captcha').click(function () {
        this.src = this.src + '?t=' + (new Date).getTime();
    });
    /*layui.use(['form','layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            layer.load(2);
            $.post('${pageContext.request.contextPath}/login/login', obj.field, function (data) {
                if ('success' == data.success) {
                    layer.msg('登录成功', {icon: 1, time: 1500}, function () {
                        location.replace('./main');
                    });
                } else if(data.error == 'error'){
                    layer.closeAll('loading');
                    layer.msg("您请输入的用户名或密码错误！！！", {icon: 5});
                    $('.login-captcha').trigger('click');
                }else {
                    layer.closeAll('loading');
                    layer.msg("请输入用户名或密码！！！", {icon: 5});
                    $('.login-captcha').trigger('click');
                }
            }, 'JSON');
            return false;
        });

    })
    */


    /*
    function ajaxLogin() {

        var username = $('#username').val();
        var password = $('#password').val();
        $.ajax({
            url:'${pageContext.request.contextPath}/login/login',
            type:'post',
            dataType:'json',
            data:{username:username,password:password},
            success(data){
                if(data.blank == 'blank'){
                    alert('请输入用户名或密码！！！')
                    //layer.alert('请输入用户名或密码！！！');
                } else if(data.error == 'error'){
                    alert('您请输入的用户名或密码错误！！！')
                    //layer.msg('您请输入的用户名或密码错误！！！', {icon: 3});
                } else{
                    window.location="${pageContext.request.contextPath}/login/main";
                    // window.location="http://www.baidu.com";
                }

            }
        })
    }
*/



</script>
</body>
</html>
